package com.wowudi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wowudi.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wowudi.mapper.DrugMapper;
import com.wowudi.domain.Drug;

import java.util.List;

@Service
public class DrugServiceImpl extends ServiceImpl<DrugMapper, Drug> implements DrugService {

    @Autowired
    DrugMapper DrugMapper;


    @Override
    public Page findAllBySearch(int size,int current,String name) {
        Page Page=new Page();
        Page.setSize(size);
        Page.setCurrent(current);
        QueryWrapper<Drug> Drug=new QueryWrapper<Drug>();
        Drug.like("d_name",name).or().like("d_brand",name);
        return DrugMapper.selectMapsPage(Page,Drug);
    }

    @Override
    public boolean updateStatusById(String status,int id) {
        return DrugMapper.updateStatusById(status,id);
    }

    @Override
    public boolean addDrug(Drug Drug) {
        return DrugMapper.insert(Drug)>0?true:false;
    }

    @Override
    public boolean delDrugById(int id) {
        return DrugMapper.deleteById(id)>0?true:false;
    }

    @Override
    public Drug findById(int id) {
        Drug Drug= DrugMapper.selectById(id);
        return Drug;
    }

    @Override
    public boolean updateById(Drug Drug) {
        return DrugMapper.updateById(Drug)>0?true:false;
    }

}
